import { AddressItem } from "@/type/addressTypes"
import { OrderInfo, OrderInfoItem, SubmitOrder, WxPayInfo } from "@/type/orderTypes"
import { ResponseType } from "@/type/response"
import request from "@/utils/request"
enum Enum {
  findOrderInfoAPI = "/order/trade",
  findOrderAddressAPI = "/userAddress/getOrderAddress",
  findBuyOrderInfoAPI = "/order/buy",
  submitOrderAPI = "/order/submitOrder",
  createJsAPI = "/webChat/createJsapi",
  queryPayStatusAPI = "/webChat/queryPayStatus",
  fetchOrderListAPI = "/order/order"
}

/**
 * 
 * @description 获取订单详情的接口
 */
export const findOrderInfoAPI = () => request.get<ResponseType<OrderInfo>>(Enum.findOrderInfoAPI)

/**
 * 
 * @description 获取订单地址的接口
 */
export const findOrderAddressAPI = () => request.get<ResponseType<AddressItem>>(Enum.findOrderAddressAPI)

/**
 *
 * @description 获取立即购买订单详情的接口
 */
export const findBuyOrderInfoAPI = (goodsId: number, blessing: string) => request.get<ResponseType<OrderInfo>>(`${Enum.findBuyOrderInfoAPI}/${goodsId}`, { blessing })

/**
 * 
 * @description 提交订单的接口
 */
export const submitOrderAPI = (submitOrder: SubmitOrder) => request.post<ResponseType<string>>(Enum.submitOrderAPI, submitOrder)

/**
 * @description 获取微信预支付信息的接口
 */
export const createJsAPI = (orderId: string) => request.get<ResponseType<WxPayInfo>>(`${Enum.createJsAPI}/${orderId}`)

/**
 * 
 * @description 微信支付状态查询的接口
 */
export const queryPayStatusAPI = (orderId: string) => request.get<ResponseType<string>>(`${Enum.queryPayStatusAPI}/${orderId}`)


/**
 * 
 * @description 获取订单列表的接口
 */
export const fetchOrderListAPI = (page: number, limit: number) => request.get<ResponseType<any[]>>(`${Enum.fetchOrderListAPI}/${page}${limit}`)